import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class updatedemo {
    public static void main(String[] args) throws SQLException {
        DataSource datasource=new MysqlDataSource();
        ((MysqlDataSource)datasource).setURL("jdbc:mysql://127.0.0.1:3306/java_114?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)datasource).setUser("root");
        ((MysqlDataSource)datasource).setPassword("1291691906");
        Scanner scanner=new Scanner(System.in);

        System.out.println("请输入id");
        int id=scanner.nextInt();

        System.out.println("请输入name");
        String name=scanner.next();
        Connection connection=datasource.getConnection();
        String sql="update student set id=? where name=?";
        PreparedStatement statement=connection.prepareStatement(sql);

        statement.setInt(1,id);
        statement.setString(2,name);


        //statement.setString(2,name);
        int ret=statement.executeUpdate();
        System.out.println(ret);
        System.out.println(statement);
        statement.close();
        connection.close();

    }
}
